'use strict';

/**
 * 设备管理，巨龙_jHD23设备，已启用，字段合并到ipc
 */
const mongoose = require('mongoose'), Schema = mongoose.Schema;
const OPEN_STATUS = 1, CLOSE_STATUS = 2;
const deviceSchema = new Schema({
    device_id: {type:String},
    device_ip: {
        type: String,
        // validate: function(v,cb){
        //     const ipRegex = /\d{3}\.\d{3}\.\d{1,3}\.\d{1,3}/
        //     cb(ipRegex.test(v), 'ip地址格式不规范')
        // },
        // required: [true, '请输入ip地址']
    }, //ip地址
    device_uuid: {type: String}, //uuid
    device_mac: {type: String}, //mac地址
    device_type: {type: Number},//设备类型
    device_code: {type: String}, //设备编号
    device_address: {type: String},//设备地址
    device_status: {type: Number},//设备状态 1正常 2关闭或再重启 3已配置,连接异常 4未配置
    device_group: {type: Number},//设备组
    s_n: {type: String}, //序列号
    channel_num: { 
        type: Number,
        // required: [true, '请输入通道数']
    },//通道数
    web_version: {type: String},//页面版本
    core_version: {type: String},//主程序版本
    version_date: {type: String},//版本日期
    http_version: {type: String},//HTTP协议版本
    http_date: {type: String},//HTTP协议版本日期
    register_session: {type: String},//注册Session
    alarm_switch: {type: Number, default: OPEN_STATUS}, //报警开关
    black_alarm_switch: {type: Number, default: OPEN_STATUS}, //黑名单报警开关
    white_alarm_switch: {type: Number, default: CLOSE_STATUS}, //白名单报警开关
    io_switch: {type: Number, default: CLOSE_STATUS}, //IO输出
    io_type: {type: Number},//io输入类型，1持续输出，2脉冲输出
    alarm_duration: {type: Number}, //报警持续时间(s)
    io_status_type: {type: Number}, //IO输出状态类型，1常开，2常闭
    recognition_mode: {type: Number}, //识别模式，1一直识别，2次数识别，3单张识别
    similarity_set: {type:Number}, //比对相似度, 1~100
    alarm_start_time: {type: String},//布防时间段
    alarm_end_time: {type: String},//布防时间段
    subnet_mask: {type: String},//子网掩码
    gateway: {type: String},//网关
    preferred_dns: {type: String},//首选DNS地址
    standby_dns: {type: String},//备用DNS地址
})

module.exports = mongoose.model('deviceSchema', deviceSchema, 'device')